home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / LabelMenu / InitMac.c next >
Encoding:
Text File  |  1995-06-16  |  3.3 KB  |  143 lines  |  [TEXT/MMCC]

  1. //
  2. //    File:            InitMac.c
  3. //    
  4. //    Description:    A simple set of routines to initialize the various
  5. //                    managers ang check Gestalt for Color QuickDraw
  6. //
  7. //    Programmer:        David Hayward
  8. //                    Developer Technical Support
  9. //                    Apple Computer, Inc.
  10. //
  11. //    Environment:    Metrowerks C version 6, Universal Interfaces 2.0
  12. //
  13. //    History:        2/27/94
  14. //                      first draft
  15. //                    5/12/95
  16. //                      updated project for Metrowerks
  17. //    
  18.  
  19.  
  20. #include <Dialogs.h>
  21. #include <Memory.h>
  22. #include <Windows.h>
  23. #include <QuickDraw.h>
  24. #include <Fonts.h>
  25. #include <GestaltEQU.h>
  26. #include <Traps.h>
  27. #include <TextEdit.h>
  28. #include <OSUtils.h>
  29.  
  30. #include "InitMac.h"
  31.  
  32. #define TrapMask 0x0800
  33.  
  34.  
  35. /**\
  36. |**| ==============================================================================
  37. |**| GLOBALS
  38. |**| ==============================================================================
  39. \**/
  40. SysEnvRec    TheWorld;
  41. Boolean        WNE_available;
  42. Boolean        HasGWorlds;
  43. Boolean        HasCQD;
  44.  
  45.  
  46.  
  47. /*------------------------------------------------------------------------------*\
  48.     NumToolboxTraps
  49. \*------------------------------------------------------------------------------*/
  50. short NumToolboxTraps (void)
  51. {
  52.     if (NGetTrapAddress(_InitGraf, ToolTrap) ==
  53.             NGetTrapAddress(0xAA6E, ToolTrap))
  54.         return(0x0200);
  55.     else
  56.         return(0x0400);
  57. }
  58.  
  59.  
  60. /*------------------------------------------------------------------------------*\
  61.     GetTrapType
  62. \*------------------------------------------------------------------------------*/
  63. TrapType GetTrapType (short theTrap)
  64. {
  65.     if ((theTrap & TrapMask) > 0)
  66.         return(ToolTrap);
  67.     else
  68.         return(OSTrap);
  69. }
  70.  
  71.  
  72. /*------------------------------------------------------------------------------*\
  73.     TrapAvailable
  74. \*------------------------------------------------------------------------------*/
  75. Boolean TrapAvailable (short theTrap)
  76. {
  77.  
  78.     TrapType    tType;
  79.  
  80.     tType = GetTrapType(theTrap);
  81.     if (tType == ToolTrap)
  82.         theTrap &= 0x07FF;
  83.     if (theTrap >= NumToolboxTraps())
  84.         theTrap = _Unimplemented;
  85.  
  86.     return (NGetTrapAddress(theTrap, tType) !=
  87.             NGetTrapAddress(_Unimplemented, ToolTrap));
  88. }
  89.  
  90.  
  91. /*------------------------------------------------------------------------------*\
  92.     WNEAvailable
  93. \*------------------------------------------------------------------------------*/
  94. Boolean WNEAvailable (void)
  95. {
  96.     return TrapAvailable(_WaitNextEvent);
  97. }
  98.  
  99.  
  100. /*------------------------------------------------------------------------------*\
  101.     CheckQuickDraw
  102. \*------------------------------------------------------------------------------*/
  103. void CheckQuickDraw (void)
  104. {
  105.     long      QDvers;  /* Version of QuickDraw on this machine */
  106.     
  107.     /* Find out if GWorlds and CQD are implemented on this machine */
  108.     Gestalt(gestaltQuickdrawVersion, &QDvers);
  109.  
  110.     HasGWorlds = (QDvers > gestaltOriginalQD && QDvers < gestalt8BitQD)
  111.                   || QDvers >= gestalt32BitQD;
  112.     
  113.     HasCQD = (QDvers >= gestalt8BitQD);
  114. }
  115.  
  116.  
  117. /*------------------------------------------------------------------------------*\
  118.     InitToolBox
  119. \*------------------------------------------------------------------------------*/
  120. void InitToolBox (short numberOfMasters)
  121. {
  122.     
  123.     InitGraf((Ptr) &qd.thePort);
  124.     InitFonts();
  125.     InitWindows();
  126.     InitMenus();
  127.     InitCursor();
  128.     TEInit();
  129.     FlushEvents(everyEvent, 0);
  130.     InitDialogs(nil);
  131.     
  132.     while(numberOfMasters--)
  133.         MoreMasters();
  134.         
  135.     MaxApplZone();
  136.     
  137.     SysEnvirons(1,&TheWorld);
  138.     
  139.     WNE_available = WNEAvailable();
  140.  
  141.     CheckQuickDraw ();
  142. }
  143.